﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Web_HengliSeed.Sys_Manage
{
    public partial class M_ProductList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ClassFile.Function.CheckState();
            if (!IsPostBack)
            {
                BindData("");
                BindDDL();
            }
        }

        private void BindDDL()
        {
            string lan = "cn";
            if (!String.IsNullOrEmpty(Request["lan"]))
                lan = Request["lan"];

            DDLProClass.DataSource = BLL.ProductInfo.GetClassMesAll(lan);
            DDLProClass.DataTextField = "T_ProClassName";
            DDLProClass.DataValueField = "T_ProClassID";
            DDLProClass.DataBind();
        }
        private void BindData(string strClass)
        {
            int DataCount = 0;
            int NowPage = 1;
            int AllPage = 0;
            int PageSize = Convert.ToInt32(HPageSize.Value);
            switch (strClass)
            {
                case "next":
                    NowPage = Convert.ToInt32(HNowPage.Value) + 1;
                    break;
                case "up":
                    NowPage = Convert.ToInt32(HNowPage.Value) - 1;
                    break;
                case "end":
                    NowPage = Convert.ToInt32(HAllPage.Value);
                    break;
                default:
                    break;
            }
            string lan = "cn";
            if (!String.IsNullOrEmpty(Request["lan"]))
                lan = Request["lan"];

            DataTable dsLog = BLL.ProductInfo.GetAllProductInfo(NowPage, PageSize, out AllPage, out DataCount, HWhere.Value, lan);
            if (dsLog.Rows.Count == 0 || AllPage==1)
            {
                LBEnd.Enabled = false;
                LBHome.Enabled = false;
                LBNext.Enabled = false;
                LBUp.Enabled = false;
            }
            else if (NowPage == 1)
            {
                LBHome.Enabled = false;
                LBUp.Enabled = false;
                LBNext.Enabled = true;
                LBEnd.Enabled = true;
            }
            else if (NowPage == AllPage)
            {
                LBHome.Enabled = true;
                LBUp.Enabled = true;
                LBNext.Enabled = false;
                LBEnd.Enabled = false;
            }
            else
            {
                LBEnd.Enabled = true;
                LBHome.Enabled = true;
                LBNext.Enabled = true;
                LBUp.Enabled = true;
            }
            RpProduct.DataSource = dsLog;
            RpProduct.DataBind();
            PageMes.Text = string.Format("[每页<font color=green>{0}</font>条 第<font color=red>{1}</font>页／共<font color=green>{2}</font>页   共<font color=green>{3}</font>条]", PageSize, NowPage, AllPage, DataCount);
            HNowPage.Value = Convert.ToString(NowPage++);
            HAllPage.Value = AllPage.ToString();
        }
        protected void LBHome_Click(object sender, EventArgs e)
        {
            BindData("");
        }

        protected void LBUp_Click(object sender, EventArgs e)
        {
            BindData("up");
        }

        protected void LBNext_Click(object sender, EventArgs e)
        {
            BindData("next");
        }

        protected void LBEnd_Click(object sender, EventArgs e)
        {
            BindData("end");
        }

        protected void BtnAllDel_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(HSelectID.Value.Trim()))
            {
                if (BLL.ProductInfo.DelProductInfo(HSelectID.Value.Trim()))
                {
                    Common.ShowMessage.Show(Page, "suess", "指定信息成功删除..", "M_ProductList.aspx");
                }
                else
                {
                    Common.ShowMessage.Show(Page, "error", "指定信息删除失败，请重试或联系技术人员..");
                }
            }
        }

        protected void DDLProClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DDLProClass.SelectedValue!="0")
            {
                HWhere.Value = " WHERE T_ProClassID="+DDLProClass.SelectedValue;
            }
            BindData("");
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("M_EditProductInfo.aspx?lan=" + Request["lan"]);
        }
    }
}
